﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Expenses
{
    public class PresenterSearchExpense
    {
        ISearchExpenseView view;

        public PresenterSearchExpense(ISearchExpenseView view)
        {
            this.view = view;
        }

        public void SearchWaterPurchase()
        {
            bool entra = true;
            try
            {
                Model.Expense u = new Model.Expense() { ExpenseType = view.Item, Receipt = view.Receipt};

                try
                {
                    u.SpendDate = view.SpendDate;
                }
                catch (Exception ex)
                {
                    entra = false;
                }
                if (entra)
                    view.ExpenseFinded = ManagerExpense.SearchExpenseByParameter(u);
                else
                    view.ExpenseFinded = ManagerExpense.SearchExpenseMinusDate(u);

            }
            catch (Exception ex)
            {
                view.ExpenseFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }

        private void CleanSearch()
        {
            view.Receipt = string.Empty;
            view.ExpenseFinded = new Collection<Model.Expense>();
        }


    }
}
